Skip to content

Wrap dask_setup scripts in if __name__ == "__main__" guard; use threaded scheduler for import scripts#127

Merged
akhanf merged 10 commits intoperf-updatesfrom
copilot/update-scripts-to-use-main-block
Mar 10, 2026
Merged

Wrap dask_setup scripts in if __name__ == "__main__" guard; use threaded scheduler for import scripts#127
akhanf merged 10 commits intoperf-updatesfrom
copilot/update-scripts-to-use-main-block

Conversation

Copy link
Contributor

Copilot AI commented Mar 10, 2026

When using dask.distributed, worker processes are forked and re-import the script, causing top-level code to execute unintentionally. All scripts using get_dask_client must gate execution behind if __name__ == "__main__":.

Changes

  • All 14 dask_setup scripts — moved all code (including any pre-with get_dask_client(...) setup that accesses snakemake) inside if __name__ == "__main__":

  • 3 scripts hardcoded to "threads" schedulerome_zarr_to_nii.py, create_imaris_crops.py, create_patches.py now bypass snakemake.config["dask_scheduler"] and always use the threaded scheduler:

# Before
with get_dask_client(snakemake.config["dask_scheduler"], snakemake.threads):
    ...

# After
if __name__ == "__main__":
    with get_dask_client("threads", snakemake.threads):
        ...

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

…scheduler for ome_zarr_to_nii, create_imaris_crops, create_patches

Co-authored-by: akhanf <11492701+akhanf@users.noreply.github.com>
Copilot AI changed the title [WIP] Update Python scripts to use main block and threaded execution Wrap dask_setup scripts in if __name__ == "__main__" guard; use threaded scheduler for import scripts Mar 10, 2026
@akhanf akhanf marked this pull request as ready for review March 10, 2026 13:46
@akhanf akhanf merged commit a9cba48 into perf-updates Mar 10, 2026
1 of 2 checks passed
@akhanf akhanf deleted the copilot/update-scripts-to-use-main-block branch March 10, 2026 13:48
akhanf added a commit that referenced this pull request Mar 14, 2026
* localrule and cpus for vesselfm

* more fixes

* remove job grouping, update perf

* add group_jobs to temp() outputs with work

* update group_jobs and resources

* fix

* Wrap dask_setup scripts in `if __name__ == "__main__"` guard; use threaded scheduler for import scripts (#127)

* Wrap dask_setup scripts in if __name__ == "__main__" and force threads scheduler for certain jobs

* fixes

* update  runtimes

* retain .ozx (zip ome zarr) instead of only temp ome.zarr

still written to tmp first, then  zipped to shared fs. hopefully still
is fast for reading, but ultimately ideal for retaining outputs

* up short runtimes

* use otsu only

* reduce memory

* don't save upsampled bias field

* update resources, chunks, and no patches by default

* another resource fitx

* update resources

* adjust resources

* fix resources

* bugfix for zarrnii units, was incorrectly changing units

related to zarrnii issue #203, fix here in any case

* fmt

---------

Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants